package com.yangzheandroid.rxmvp;

import android.app.Application;

import com.uuzuche.lib_zxing.activity.ZXingLibrary;
import com.yangzhe.okhttputils.OkHttpUtils;
import com.yangzhe.okhttputils.common.RequestHeaders;
import com.yangzhe.okhttputils.common.RequestParams;
import com.yangzheandroid.rxmvp.di.component.AppComponent;
import com.yangzheandroid.rxmvp.di.component.DaggerAppComponent;
import com.yangzheandroid.rxmvp.di.module.AppModule;

public class APP extends Application {

    private static APP mApplication;
    public static boolean isDebug = true;


    public static APP getInstance() {
        return mApplication;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mApplication = this;


        initOkhttp();
        init();
    }

    private void initOkhttp() {
        RequestHeaders headers = new RequestHeaders();
        headers.put("aaa", "111");

        RequestParams params = new RequestParams();
        params.put("bbb", "222");

        OkHttpUtils.getInstance()
                .debug(isDebug, "myokhttp")
                .setConnectTimeout(OkHttpUtils.DEFAULT_MILLISECONDS)//全局的连接超时时间
                .setReadTimeOut(OkHttpUtils.DEFAULT_MILLISECONDS)//全局的读取超时时间
                .setWriteTimeOut(OkHttpUtils.DEFAULT_MILLISECONDS)//全局的写入超时时间
                .addCommonHeader(headers)
                .addCommonParams(params);
    }


    private void init() {

        ZXingLibrary.initDisplayOpinion(this);
    }

    public static AppComponent appComponent;

    public static AppComponent getAppComponent(){
        if (appComponent == null) {
            appComponent = DaggerAppComponent.builder()
                    .appModule(new AppModule(mApplication))
                    .build();
        }
        return appComponent;
    }



}
